package com.fjh.controller;

import com.fjh.domain.User;
import com.fjh.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("p/user")
@Api(tags = "会员管理")
public class MemberController {

    @Autowired
    private UserService userService;

    @PutMapping("setUserInfo")
    @ApiOperation("更新用户信息")
    public ResponseEntity<Void> setUserInfo(@RequestBody User user){
        String userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        user.setUserId(userId);
        userService.updateById(user);
        return ResponseEntity.ok().build();
    }

    /**
     * 远程调用获取用户的信息集合
     * @param userIds
     * @return
     */
    @PostMapping("getUserListByIds")
    @ApiOperation("根据ids获取用户的信息集合")
    List<User> getUserListByIds(@RequestBody List<String> userIds){
        return userService.listByIds(userIds);
    }
}
